package com.cobo.fitness.core.meillisearch;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
@ConditionalOnProperty(prefix = "meilisearch",name = "enabled")
public class MeilisearchConfiguration {

    @Value("${meilisearch.master-key:masterkey:null}")
    private String masterKey;

    @Value("${meilisearch.host:null}")
    private String meilisearchHost;

    @Bean("meilisearchClient")
    public MeilisearchClient meilisearchClient() {
        DefaultMeilisearchClient defaultMeilisearchClient = new DefaultMeilisearchClient();
        defaultMeilisearchClient.setMeilisearchHost(meilisearchHost);
        defaultMeilisearchClient.setMasterKey(masterKey);
        return defaultMeilisearchClient;
    }
}
